package cn.com.generaldata.os.service.indicator_evaluation.national_economy_contribution;

import org.apache.commons.lang3.Validate;
import org.nutz.dao.sql.Criteria;

import cn.com.generaldata.jsme_indicator_system.entity.IndicatorEvaluation;
import cn.com.generaldata.os.service.indicator_constant.ProvinceIndicatorConstant;
import cn.com.generaldata.os.service.indicator_evaluation.IndicatorEvaluationCalculateService;
import cn.com.generaldata.os.vo.IndicatorAccountVO;

/**
 * 涉海就业对全国就业的拉动评估指标计算类.
 */
public class OceanRelatedEmployedPullCalculateService extends IndicatorEvaluationCalculateService {

	private String employedIndicatorName = ProvinceIndicatorConstant.EMPLOYED_INDICATOR_NAME;
	private String oceanRelatedEmployedContributionIndicatorName = ProvinceIndicatorConstant.OCEAN_EMPLOYED_CONTRIBUTION_INDICATOR_NAME;

	@SuppressWarnings("null")
	@Override
	protected Double calculate(IndicatorEvaluation indicator, IndicatorAccountVO indicatorAccountVO) {

		Double currentEmployedCount = getInputOrAccountingIndicatorValue(indicatorAccountVO,
				indicatorAccountVO.getYear(),
				employedIndicatorName);
		Validate.isTrue(currentEmployedCount != null);

		Double prevEmployedCount = getInputOrAccountingIndicatorValue(indicatorAccountVO,
				indicatorAccountVO.getYear() - 1, employedIndicatorName);

		Validate.isTrue(prevEmployedCount != null);

		Double employedGrowth = (currentEmployedCount - prevEmployedCount) / prevEmployedCount;

		Double oceanRelatedEmployedContribution = getOceanRelatedEmployedContribution(indicatorAccountVO);

		return employedGrowth * oceanRelatedEmployedContribution;
	}

	private Double getOceanRelatedEmployedContribution(IndicatorAccountVO indicatorAccountVO) {
		Integer indicatorInputId = getIndicatorEvaluationId(oceanRelatedEmployedContributionIndicatorName,
				indicatorAccountVO.getAreaId());

		Criteria cri = getIndicatorDataCri(indicatorAccountVO, indicatorAccountVO.getYear(), indicatorInputId);
		Double result = getEvaluationIndicatorValue(cri);
		Validate.isTrue(result != null);
		return result;

	}

}
